package com.xjtu.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.xjtu.dto.UserPageDto;
import com.xjtu.entity.Elderly;
import com.xjtu.exception.BaseException;
import com.xjtu.mapper.ElderlyMapper;
import com.xjtu.result.PageResult;
import com.xjtu.service.ElderlyService;
import com.xjtu.vo.ElderlyVo;
import com.xjtu.vo.UserVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
public class ElderlyServiceImpl implements ElderlyService {
    @Autowired(required = false)
    private ElderlyMapper elderlyMapper;
    @Override
    public Elderly queryById(Integer id) {
        Elderly elderly = elderlyMapper.selectByPrimaryKey(Long.valueOf(id));
        if(elderly == null){
            throw new BaseException("id错误,记录不存在");
        }
        return elderly;
    }

    @Override
    public PageResult pageQuery(Integer page, Integer size, String name) {
        PageHelper.startPage(page, size);
        Page<Elderly> userPage = elderlyMapper.pageQuery(name);
        long total = userPage.getTotal();
        List<Elderly> records = userPage.getResult();
        return new PageResult(total, records);
    }

    @Override
    public List<Elderly> getAll() {
        List<Elderly> resp = elderlyMapper.selectAll();
        return resp;
    }
}
